﻿using System.Collections.Generic;
using System.Linq;

namespace LuatChoi
{
    public class Ma : QuanCo
    {
        public Ma()
        {
        }

        public Ma(Phe mau, BanCo banCo, int x, int y)
        {
            ToaDo = new Vector(x, y);
            Ban = banCo;
            Mau = mau;
        }

        public override void TinhToaDoAnhHuong()
        {
            ToaDoCoTheDiChuyen = new List<Vector>();
            int x = ToaDo.X;
            int y = ToaDo.Y;

            //danh sách các bước nhảy
            var dsBuocNhay = new List<Vector>
                {
                    new Vector(x + 1, y + 2),
                    new Vector(x + 2, y + 1),
                    new Vector(x + 2, y - 1),
                    new Vector(x + 1, y - 2),
                    new Vector(x - 1, y - 2),
                    new Vector(x - 2, y - 1),
                    new Vector(x - 2, y + 1),
                    new Vector(x - 1, y + 2),
                };

            //danh sách các tọa độ nằm trong bàn cờ
            IEnumerable<Vector> dsKhaDung = from vector in dsBuocNhay
                                            where vector.X <= 7 && vector.Y <= 7 && vector.X >= 0 && vector.Y >= 0
                                            select vector;

            ToaDoCoTheTanCong = (from vector in dsKhaDung
                                 where Ban[vector.X, vector.Y] != null && !Ban[vector.X, vector.Y].Mau.Equals(Mau)
                                 select vector).ToList();

            ToaDoCoTheDiChuyen = (from vector in dsKhaDung
                                  where Ban[vector.X, vector.Y] == null
                                  select vector).ToList();
        }
    }
}